'''
Author: caishuyang
Date: 2023-01-08 16:22:46
LastEditors: caishuyang
LastEditTime: 2023-01-08 16:50:03
Description: 
'''
import yaml
import math


class Contain():
    def __init__(self):

        self.name = 'Contain'

        self.R = 0.1
        self.rotR = 0.2
        self.t = 0
        self.omiga = 1

        self.x=0
        self.y=0
        self.vx=0
        self.vy=0
        self.readParam()
        self.getAll()

    def readParam(self):
        yamlPath = 'config.yaml'
        flag = True
        try:
            f = open(yamlPath, 'r', encoding='utf-8')
        except:
            print('无法打开', yamlPath)
            flag = False
        if flag:
            cont = f.read()
            param = yaml.load(cont, Loader=yaml.FullLoader)
            dic = param[self.name]
            self.R = float(dic['R'])
            self.rotR = float(dic['rotR'])
            self.t = float(dic['t'])
            self.omiga = float(dic['omiga'])

    def getAll(self):
        self.x = math.cos(self.omiga*self.t)*self.rotR
        self.y = math.sin(self.omiga*self.t)*self.rotR
        self.vx = -self.omiga*math.sin(self.omiga*self.t)*self.rotR
        self.vy = self.omiga*math.cos(self.omiga*self.t)*self.rotR

    def __str__(self):
        return self.name
